/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import model.Dokument;
import model.OraConnection;
import model.Surat;

/**
 *
 * @author TOSHIBA
 */
public class FrameUtamaDosen extends JFrame {

    private JMenuBar menubar;
    private JMenu menuPeriksa;
    private JMenuItem menuSurat, menuDokumen;
    private ArrayList<Dokument> data;
    private ArrayList<Surat> dok;

    public FrameUtamaDosen(){
        inisialisasi();
    }

    public void inisialisasi() {
        setLayout(null);
        setTitle("Frame Utama Dosen");

        menubar = new JMenuBar();
        setJMenuBar(menubar);

        menuPeriksa = new JMenu("Periksa Surat Dokumen");
        menubar.add(menuPeriksa);

        menuDokumen = new JMenuItem("Lihat Dokumen");
//        menuDokumen.setBounds(50, 100, 150, 20);
        menuPeriksa.add(menuDokumen);
        menuDokumen.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                menuLihatDaftarDokumenAction();
            }
        });

        menuSurat = new JMenuItem("Lihat Surat");
//        menuSurat.setBounds(250, 100, 150, 20);
        menuPeriksa.add(menuSurat);
        menuSurat.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                menuLihatDaftarSuratAction();
            }
        });

    }

    public void menuLihatDaftarDokumenAction() {
        data = new ArrayList<Dokument>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314063", "MHS115314063");
        Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "select * from surat";
        try {
            statement.execute(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet set = null;
        try {
            set = statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (set.next()) {
                Dokument dok = new Dokument();
                dok.setNomorDokument(set.getInt(1));
                dok.setPerihal(set.getString(2));
                dok.setAsalDokumen(set.getString(3));
                dok.setPenerimaDokumen(set.getString(4));
                dok.setTanggalTerima(set.getString(5));
                dok.setTempatPenyimpanan(set.getString(6));
                dok.setPetugasPenerima(set.getString(7));
                dok.setKeterangan(set.getString(8));
                data.add(dok);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }

        PanelDaftarDokument panelDaftar = new PanelDaftarDokument(data);
        JFrame test2 = new JFrame();
        test2.getContentPane().add(panelDaftar);
        test2.setTitle("Daftar Dokument");
        test2.setSize(430, 300);
        test2.setVisible(true);
    }

    public void menuLihatDaftarSuratAction() {
        dok = new ArrayList<Surat>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314063", "MHS115314063");
        Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "select * from dokumen";
        try {
            statement.execute(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        ResultSet set = null;
        try {
            set = statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (set.next()) {
                Surat s = new Surat();
                s.setNomorSurat(set.getInt(1));
                s.setPerihal(set.getString(2));
                s.setAsalSurat(set.getString(3));
                s.setPenerimaSurat(set.getString(4));
                s.setTanggalTerima(set.getString(5));
                s.setLetakSurat(set.getString(6));
                s.setPetugasPenerima(set.getString(7));
                s.setKeterangan(set.getString(8));
                dok.add(s);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PanelPeriksaSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
        PanelDaftarSurat panelDaftar = new PanelDaftarSurat(dok);
        JFrame test2 = new JFrame();
        test2.getContentPane().add(panelDaftar);
        test2.setTitle("Daftar Suratt");
        test2.setSize(430, 300);
        test2.setVisible(true);
    }
}
